package com.ruoyi.ryzs.controller;

import java.util.Arrays;
import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.ryzs.domain.RyzsExportDTO;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.ryzs.domain.BusinessRyzs;
import com.ruoyi.ryzs.service.IBusinessRyzsService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 人鱼助手Controller
 *
 * @author nanqiang
 * @date 2022-06-07
 */
@RestController("BusinessRyzsController")
@RequestMapping("/ryzs/ryzs")
public class BusinessRyzsController extends BaseController
{
    @Autowired
    private IBusinessRyzsService businessRyzsService;

    /**
     * 查询人鱼助手列表
     */
    @PreAuthorize("@ss.hasPermi('ryzs:ryzs:list')")
    @GetMapping("/list")
    public TableDataInfo list(BusinessRyzs businessRyzs)
    {
        startPage();
        List<BusinessRyzs> list = businessRyzsService.selectBusinessRyzsList(businessRyzs);
        return getDataTable(list);
    }

    /**
     * 导出人鱼助手列表
     */
    @PreAuthorize("@ss.hasPermi('ryzs:ryzs:export')")
    @Log(title = "人鱼助手", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BusinessRyzs businessRyzs)
    {
        List<BusinessRyzs> list = businessRyzsService.selectBusinessRyzsList(businessRyzs);
        ExcelUtil<BusinessRyzs> util = new ExcelUtil<BusinessRyzs>(BusinessRyzs.class);
        util.exportExcel(response, list, "人鱼助手数据");
    }


    @Log(title = "人鱼助手导出卡密", businessType = BusinessType.EXPORT)
    @PostMapping("/exportQuantity")
    public void exportQuantity(HttpServletResponse response, RyzsExportDTO exportDTO)
    {
        businessRyzsService.exportQuantity(response, exportDTO);
    }


    /**
     * 获取人鱼助手详细信息
     */
    @PreAuthorize("@ss.hasPermi('ryzs:ryzs:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(businessRyzsService.getById(id));
    }

    /**
     * 新增人鱼助手
     */
    @PreAuthorize("@ss.hasPermi('ryzs:ryzs:add')")
    @Log(title = "人鱼助手", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BusinessRyzs businessRyzs) {
        return toAjax(businessRyzsService.save(businessRyzs));
    }

    /**
     * 修改人鱼助手
     */
    @PreAuthorize("@ss.hasPermi('ryzs:ryzs:edit')")
    @Log(title = "人鱼助手", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BusinessRyzs businessRyzs) {
        return toAjax(businessRyzsService.updateById(businessRyzs));
    }

    /**
     * 删除人鱼助手
     */
    @PreAuthorize("@ss.hasPermi('ryzs:ryzs:remove')")
    @Log(title = "人鱼助手", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(businessRyzsService.removeByIds(Arrays.asList(ids)));
    }

    /**
     * 邀请20人
     */
    @PostMapping("/invitation")
    public AjaxResult invitation()
    {
        businessRyzsService.invitation();
        return AjaxResult.success();
    }

    /**
     * 批量登录
     */
    @PostMapping("/batchSignIn")
    public AjaxResult batchSignIn()
    {
        return AjaxResult.success(businessRyzsService.batchSignIn());
    }
}
